#include "TTable.h"

void TTable::SolidWire(bool value)
{
	wireFrame = value;
}

void TTable::Rotate(float x,float y)
{
	xRot = x;
	yRot = y;
}

void TTable::Position(float xMove, float yMove, float zMove)
{
	x=xMove;
	y=yMove;
	z=zMove;
}

void TTable::RenderLegs()
{

	//width : 50
	//height : 10
	//depth : 50

	//right front leg
		//front face
		//white
        glColor3f(1.0f, 1.0f, 1.0f);
		glNormal3f(0.0f,0.0f,1.0f);
        glVertex3f(50.0f,-10.0f,50.0f);
        glVertex3f(50.0f,-50.0f,50.0f);
        glVertex3f(40.0f,-50.0f,50.0f);
        glVertex3f(40.0f,-10.0f,50.0f);

	
		// Back Face
        // Green
        glColor3f(0.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,0.0f,-1.0f);
        glVertex3f(50.0,-10.0f,40.0f);
        glVertex3f(50.0,-50.0f,40.0f);
        glVertex3f(40.0,-50.0f,40.0f);
        glVertex3f(40.0,-10.0f,40.0f);
	
		//// Top Face
  //      // Cyan
  //      glColor3f(0.0f, 1.0f, 1.0f);
		//glNormal3f(0.0f,1.0f,0.0f);
  //      glVertex3f(50.0f,-10.0f,-10.0f);
  //      glVertex3f(50.0f,-10.0f,0.0f);
  //      glVertex3f(40.0f,-10.0f,0.0f);
  //      glVertex3f(40.0f,-10.0f,-10.0f);
	
	// Bottom Face
        // Yellow
        glColor3f(1.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,-1.0f,0.0f);
        glVertex3f(50.0f,-50.0f,50.0f);
        glVertex3f(50.0f,-50.0f,40.0f);
        glVertex3f(40.0f,-50.0f,40.0f);
        glVertex3f(40.0f,-50.0f,50.0f);
	
	// right face
        // Blue
        glColor3f(0.0f, 0.0f, 1.0f);
		glNormal3f(1.0f,0.0f,0.0f);
        glVertex3f(50.0f,-10.0f,40.0f);
        glVertex3f(50.0f,-10.0f,50.0f);
        glVertex3f(50.0f,-50.0f,50.0f);
        glVertex3f(50.0f,-50.0f,40.0f);
	
		// left face
        // Magenta
        glColor3f(1.0f, 0.0f, 1.0f);
		glNormal3f(-1.0f,0.0f,0.0f);
        glVertex3f(40.0f,-10.0f,40.0f);
        glVertex3f(40.0f,-10.0f,50.0f);
        glVertex3f(40.0f,-50.0f,50.0f);
        glVertex3f(40.0f,-50.0f,40.0f);


	//left front leg
		//front face
		//white
        glColor3f(1.0f, 1.0f, 1.0f);
		glNormal3f(0.0f,0.0f,1.0f);
        glVertex3f(-50.0f,-10.0f,50.0f);
        glVertex3f(-50.0f,-50.0f,50.0f);
        glVertex3f(-40.0f,-50.0f,50.0f);
        glVertex3f(-40.0f,-10.0f,50.0f);

	
		// Back Face
        // Green
        glColor3f(0.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,0.0f,-1.0f);
        glVertex3f(-50.0,-10.0f,40.0f);
        glVertex3f(-50.0,-50.0f,40.0f);
        glVertex3f(-40.0,-50.0f,40.0f);
        glVertex3f(-40.0,-10.0f,40.0f);
	

		// Bottom Face
        // Yellow
        glColor3f(1.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,-1.0f,0.0f);
        glVertex3f(-50.0f,-50.0f,50.0f);
        glVertex3f(-50.0f,-50.0f,40.0f);
        glVertex3f(-40.0f,-50.0f,40.0f);
        glVertex3f(-40.0f,-50.0f,50.0f);
	
		// right face
        // Blue
        glColor3f(0.0f, 0.0f, 1.0f);
		glNormal3f(1.0f,0.0f,0.0f);
        glVertex3f(-40.0f,-10.0f,40.0f);
        glVertex3f(-40.0f,-10.0f,50.0f);
        glVertex3f(-40.0f,-50.0f,50.0f);
        glVertex3f(-40.0f,-50.0f,40.0f);
	
		// left face
        // Magenta
        glColor3f(1.0f, 0.0f, 1.0f);
		glNormal3f(-1.0f,0.0f,0.0f);
        glVertex3f(-50.0f,-10.0f,40.0f);
        glVertex3f(-50.0f,-10.0f,50.0f);
        glVertex3f(-50.0f,-50.0f,50.0f);
        glVertex3f(-50.0f,-50.0f,40.0f);


	//right back leg
		//front face
		//white
        glColor3f(1.0f, 1.0f, 1.0f);
		glNormal3f(0.0f,0.0f,1.0f);
        glVertex3f(50.0f,-10.0f,-40.0f);
        glVertex3f(50.0f,-50.0f,-40.0f);
        glVertex3f(40.0f,-50.0f,-40.0f);
        glVertex3f(40.0f,-10.0f,-40.0f);

	
		// Back Face
        // Green
        glColor3f(0.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,0.0f,-1.0f);
        glVertex3f(50.0,-10.0f,-50.0f);
        glVertex3f(50.0,-50.0f,-50.0f);
        glVertex3f(40.0,-50.0f,-50.0f);
        glVertex3f(40.0,-10.0f,-50.0f);
	

	// Bottom Face
        // Yellow
        glColor3f(1.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,-1.0f,0.0f);
        glVertex3f(50.0f,-50.0f,-50.0f);
        glVertex3f(50.0f,-50.0f,-40.0f);
        glVertex3f(40.0f,-50.0f,-40.0f);
        glVertex3f(40.0f,-50.0f,-50.0f);
	
	// right face
        // Blue
        glColor3f(0.0f, 0.0f, 1.0f);
		glNormal3f(1.0f,0.0f,0.0f);
        glVertex3f(50.0f,-10.0f,-40.0f);
        glVertex3f(50.0f,-10.0f,-50.0f);
        glVertex3f(50.0f,-50.0f,-50.0f);
        glVertex3f(50.0f,-50.0f,-40.0f);
	
		// left face
        // Magenta
        glColor3f(1.0f, 0.0f, 1.0f);
		glNormal3f(-1.0f,0.0f,0.0f);
        glVertex3f(40.0f,-10.0f,-40.0f);
        glVertex3f(40.0f,-10.0f,-50.0f);
        glVertex3f(40.0f,-50.0f,-50.0f);
        glVertex3f(40.0f,-50.0f,-40.0f);


	//left back leg
		//front face
		//white
        glColor3f(1.0f, 1.0f, 1.0f);
		glNormal3f(0.0f,0.0f,1.0f);
        glVertex3f(-50.0f,-10.0f,-40.0f);
        glVertex3f(-50.0f,-50.0f,-40.0f);
        glVertex3f(-40.0f,-50.0f,-40.0f);
        glVertex3f(-40.0f,-10.0f,-40.0f);

	
		// Back Face
        // Green
        glColor3f(0.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,0.0f,-1.0f);
        glVertex3f(-50.0,-10.0f,-50.0f);
        glVertex3f(-50.0,-50.0f,-50.0f);
        glVertex3f(-40.0,-50.0f,-50.0f);
        glVertex3f(-40.0,-10.0f,-50.0f);
	

	// Bottom Face
        // Yellow
        glColor3f(1.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,-1.0f,0.0f);
        glVertex3f(-50.0f,-50.0f,-50.0f);
        glVertex3f(-50.0f,-50.0f,-40.0f);
        glVertex3f(-40.0f,-50.0f,-40.0f);
        glVertex3f(-40.0f,-50.0f,-50.0f);
	
	// right face
        // Blue
        glColor3f(0.0f, 0.0f, 1.0f);
		glNormal3f(1.0f,0.0f,0.0f);
        glVertex3f(-40.0f,-10.0f,-40.0f);
        glVertex3f(-40.0f,-10.0f,-50.0f);
        glVertex3f(-40.0f,-50.0f,-50.0f);
        glVertex3f(-40.0f,-50.0f,-40.0f);
	
		// left face
        // Magenta
        glColor3f(1.0f, 0.0f, 1.0f);
		glNormal3f(-1.0f,0.0f,0.0f);
        glVertex3f(-50.0f,-10.0f,-40.0f);
        glVertex3f(-50.0f,-10.0f,-50.0f);
        glVertex3f(-50.0f,-50.0f,-50.0f);
        glVertex3f(-50.0f,-50.0f,-40.0f);

}


void TTable::Render()
{
	float xposition = width;
	float yposition = height;
	float zposition = depth;

	GLenum decide;
	if(wireFrame)
		decide=GL_LINE;
	else
		decide=GL_FILL;

	glPushMatrix();
	glTranslatef(x, y, z);
    glRotatef(xRot, 1.0f, 0.0f, 0.0f);
    glRotatef(yRot, 0.0f, 1.0f, 0.0f);


	//glPolygonMode(GL_FRONT_AND_BACK,decide);
	glPolygonMode(GL_FRONT_AND_BACK,decide);
    glBegin(GL_QUADS);
        // Front Face
        // White
        glColor3f(1.0f, 1.0f, 1.0f);
		glNormal3f(0.0f,0.0f,1.0f);
        glVertex3f(width,height,depth);
        glVertex3f(width,-height,depth);
        glVertex3f(-width,-height,depth);
        glVertex3f(-width,height,depth);

	
		// Back Face
        // Green
        glColor3f(0.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,0.0f,-1.0f);
        glVertex3f(width,height,-depth);
        glVertex3f(width,-height,-depth);
        glVertex3f(-width,-height,-depth);
        glVertex3f(-width,height,-depth);
	
		// Top Face
        // Cyan
        glColor3f(0.0f, 1.0f, 1.0f);
		glNormal3f(0.0f,1.0f,0.0f);
        glVertex3f(width,height,-depth);
        glVertex3f(width,height,depth);
        glVertex3f(-width,height,depth);
        glVertex3f(-width,height,-depth);
	
	// Bottom Face
        // Yellow
        glColor3f(1.0f, 1.0f, 0.0f);
		glNormal3f(0.0f,-1.0f,0.0f);
        glVertex3f(width,-height,-depth);
        glVertex3f(width,-height,depth);
        glVertex3f(-width,-height,depth);
        glVertex3f(-width,-height,-depth);
	
	// Left face
        // Blue
        glColor3f(0.0f, 0.0f, 1.0f);
		glNormal3f(-1.0f,0.0f,0.0f);
        glVertex3f(width,height,depth);
        glVertex3f(width,height,-depth);
        glVertex3f(width,-height,-depth);
        glVertex3f(width,-height,depth);
	
		// Right face
        // Magenta
        glColor3f(1.0f, 0.0f, 1.0f);
		glNormal3f(1.0f,0.0f,0.0f);//right face normal sticks straight out to the right?
        glVertex3f(-width,height,depth);
        glVertex3f(-width,height,-depth);
        glVertex3f(-width,-height,-depth);
        glVertex3f(-width,-height,depth);

		RenderLegs();
	

    glEnd();


	glPopMatrix();
}
